include( "shared.lua" )

--[[---------------------------------------------------------
	GAMEMODE EVENTS
-----------------------------------------------------------]]

--[[-----------------------------------------------------]]--
--	Initialization
--[[-----------------------------------------------------]]--
function GM:Initialize()

	--	Call base initialize
	self.BaseClass:Initialize()

	--	Debug
	DEBUG:Msg( self.Name .. " has been initialized" )

end

--------------------------------------------------------------------------

// Doesn't get much simpler than this
local HideElements = { 
	["CHudHealth"] = true,
	["CHudBattery"] = true,
	["CHudAmmo"] = true,
	["CHudSecondaryAmmo"] = true
}
local function HUDShouldDraw(name)
	if (HideElements[name]) then
		return false
	end
end
hook.Add("HUDShouldDraw", "HideHUDElements", HUDShouldDraw)

// Time for our delicious hud
function DrawElementBars()
	// Don't draw if the player isn't alive.
	client = client or LocalPlayer( )
//	if( !client:Alive( ) ) then return end
	
	local HPBarTexture = surface.GetTextureID( "red_lighter" )
	local APBarTexture = surface.GetTextureID( "blue_lighter" )
	local AMBarTexture = surface.GetTextureID( "orange_lighter" )
	local HUDBrick = surface.GetTextureID( "hud_brick" )
	
	local BarHeight = 20
	local BarWidth = 220
	
	local AmmoBarHeight = 20
	local AmmoBarWidth = 160
	
	// Health and armor gathering
	local VHealth = client:Health( )
	local VSuit = client:Armor( )
	
	local MaxHealth = 100
	local MaxSuit = 100
	
	local HPercent = VHealth/MaxHealth
	local SPercent = VSuit/MaxSuit
	
	local HCurrent_Width = BarWidth * HPercent
	local SCurrent_Width = BarWidth * SPercent
	

	// Ammo value gathering
	local WepName
  	local MaxAmmo
  	local VAmmo
	local APercent = 0
	local ACurrent_Width = AmmoBarWidth * APercent
	
	if( client:GetActiveWeapon() == NULL ) then
	WepName = "None"
	MaxAmmo = 0
	VAmmo = 0
	else
	WepName = client:GetActiveWeapon():GetPrintName()
	MaxAmmo = client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType())
	VAmmo = client:GetActiveWeapon():Clip1()
	end
	
	

	
	// Team Icon
	surface.SetDrawColor(Color(100,100,100), 255)
	surface.DrawRect(( ScrW() - ScrW() / 1 ) , ( ScrH() - ScrH() / 1 ), 200, 50)

	
	surface.SetDrawColor( 150, 150, 150, 255 )
	surface.SetTexture( HUDBrick )
	surface.DrawTexturedRect( ( ScrW() - ScrW() / 1 + 5 ), ( ScrH() - ScrH() / 8 ), 256, 128 )
	
	surface.SetDrawColor( 150, 150, 150, 255 )
	surface.SetTexture( HUDBrick )
	surface.DrawTexturedRect( ( ScrW() - ScrW() / 6 + 20 ), ( ScrH() - ScrH() / 8 ), 256, 128 )
	
	// Health Bar
	surface.SetDrawColor(0, 0, 0, 255)
	surface.DrawRect(( ScrW() - ScrW() / 1 + 20 ) , ( ScrH() - ScrH() / 11 ), BarWidth, BarHeight)
//	surface.SetDrawColor(100, 0, 0, 255)
//	surface.DrawRect(( ScrW() - ScrW() / 1 ) , ( ScrH() - ScrH() / 13 ), BarWidth+8, BarHeight+8)
//	surface.SetDrawColor(255, 0, 0, 255)
//	surface.DrawRect(( ScrW() - ScrW() / 1 ) , ( ScrH() - ScrH() / 13 ), HCurrent_Width, BarHeight)

	surface.SetDrawColor( 255, 255, 255, 255 )
	surface.SetTexture( HPBarTexture )
	surface.DrawTexturedRect( ( ScrW() - ScrW() / 1 + 20 ), ( ScrH() - ScrH() / 11 ), HCurrent_Width, BarHeight )
	
	// Armor Bar
	surface.SetDrawColor(0, 0, 0, 255)
	surface.DrawRect(( ScrW() - ScrW() / 1 + 20 ) , ( ScrH() - ScrH() / 23 ), BarWidth, BarHeight)
//	surface.SetDrawColor(0, 50, 100, 255)
//	surface.DrawRect(( ScrW() - ScrW() / 1 ) , ( ScrH() - ScrH() / 25 ), BarWidth+8, BarHeight+8)
//	surface.SetDrawColor(0,150,255, 255)
//	surface.DrawRect(( ScrW() - ScrW() / 1 ) , ( ScrH() - ScrH() / 25 ), SCurrent_Width, BarHeight)

	if (VHealth <= 0) then
	surface.SetDrawColor( 0, 0, 0, 0 )
	surface.SetTexture( APBarTexture )
	surface.DrawTexturedRect( ( ScrW() - ScrW() / 1 + 20 ), ( ScrH() - ScrH() / 23 ), 0, 0 )
	else
	surface.SetDrawColor( 255, 255, 255, 255 )
	surface.SetTexture( APBarTexture )
	surface.DrawTexturedRect( ( ScrW() - ScrW() / 1 + 20 ), ( ScrH() - ScrH() / 23 ), SCurrent_Width, BarHeight )
	end
	
	// Ammo Bar
	surface.SetDrawColor(0, 0, 0, 255)
	surface.DrawRect(( ScrW() - ScrW() / 9 ) , ( ScrH() - ScrH() / 22 ), AmmoBarWidth, AmmoBarHeight)
//	surface.SetDrawColor(100, 50, 0, 255)
//	surface.DrawRect(( ScrW() - ScrW() / 9 ) , ( ScrH() - ScrH() / 22 ), AmmoBarWidth+8, AmmoBarHeight+8)
//	surface.SetDrawColor(255, 180, 0, 255)
//	surface.DrawRect(( ScrW() - ScrW() / 9 ) , ( ScrH() - ScrH() / 22 ), ACurrent_Width, AmmoBarHeight)
	
	surface.SetDrawColor( 255, 255, 255, 255 )
	surface.SetTexture( AMBarTexture )
	surface.DrawTexturedRect( ( ScrW() - ScrW() / 9 ) , ( ScrH() - ScrH() / 22 ), ACurrent_Width, BarHeight )
	
	// Team Name
	draw.SimpleText("No Team", "Trebuchet24", ScrW() - ScrW(), 25, Color(255,255,255,255), ScrW() - ScrW() / 1, ScrH() - ScrH() / 22)
	
	// Money Amount
	draw.SimpleText("SC Alpha V1.1", "Trebuchet24", ScrW() - ScrW() / 10 , 25, Color(225,255,100,255), ScrW() - ScrW() / 9, ScrH() - ScrH() / 22)
	
	// Ammo
	draw.SimpleText(VAmmo .. "/" .. MaxAmmo, "Trebuchet24", ScrW() - ScrW() / 13, ScrH() - ScrH() / 22, Color(255,255,255,255), ScrW() - ScrW() / 9, ScrH() - ScrH() / 22)
	draw.SimpleText("Ammo", "Trebuchet24", ScrW() - ScrW() / 7 - 5, ScrH() - ScrH() / 22 - 5, Color(255,215,50,255), ScrW() - ScrW() / 9, ScrH() - ScrH() / 22)
	
	// Weapon Name
	draw.SimpleText(WepName, "Trebuchet24", ScrW() - ScrW() / 8, ScrH() - ScrH() / 14 , Color(255, 200, 50,255), ScrW() - ScrW() / 9, ScrH() - ScrH() / 22)
	
	// Health Amount
	if (VHealth <= 0) then
	draw.SimpleText("*DEAD*", "Trebuchet24", ScrW() - ScrW() / 1 + 20, ScrH() - ScrH() / 11 - 5, Color(255,0,0,255), ScrW() - ScrW() / 9, ScrH() - ScrH() / 22)
	else
	draw.SimpleText(VHealth .. "/" .. MaxHealth, "Trebuchet24", ScrW() - ScrW() / 1 + 20, ScrH() - ScrH() / 11 - 5, Color(255,200,200,255), ScrW() - ScrW() / 9, ScrH() - ScrH() / 22)
	end
	draw.SimpleText("Health", "Trebuchet24", ScrW() - ScrW() / 1 + 20, ScrH() - ScrH() / 11- 25, Color(255,200,200,255), ScrW() - ScrW() / 9, ScrH() - ScrH() / 22)
	
	// Armor Amount
	if (VHealth <= 0) then
	draw.SimpleText("*DEAD*", "Trebuchet24", ScrW() - ScrW() / 1+ 20, ScrH() - ScrH() / 21, Color(255,0,0,255), ScrW() - ScrW() / 9, ScrH() - ScrH() / 22)
	else
	draw.SimpleText(VSuit .. "/" .. MaxSuit, "Trebuchet24", ScrW() - ScrW() / 1+ 20, ScrH() - ScrH() / 21, Color(200,220,255,255), ScrW() - ScrW() / 9, ScrH() - ScrH() / 22)
	end
	draw.SimpleText("Shield", "Trebuchet24", ScrW() - ScrW() / 1+ 20, ScrH() - ScrH() / 21- 20, Color(200,220,255,255), ScrW() - ScrW() / 9, ScrH() - ScrH() / 22)
 end
 hook.Add( "HUDPaint", "DrawElementBars", DrawElementBars )
 
 local enablenames = true
local enabletitles = true
local textalign = 1
// Distance multiplier. The higher this number, the further away you'll see names and titles.
local distancemulti = 2
 
 
// Name drawing from stronghold
 function DrawNameTitle()

	local vStart = LocalPlayer():GetPos()
	local vEnd
	local ply = LocalPlayer()

	for k, v in pairs(player.GetAll()) do
			local vStart = LocalPlayer():EyePos()
			local vEnd = v:EyePos()
			local trace = {}
			
			trace.start = vStart
			trace.endpos = vEnd
			local trace = util.TraceLine( trace )
			
			if trace.HitWorld then
				--Do nothing!
			else
				local mepos = LocalPlayer():GetPos()
				local tpos = v:GetPos()
				local tdist = mepos:Distance(tpos)
				
				if tdist <= 3000 then
					local zadj = 0.03334 * tdist
					local pos = v:GetPos() + Vector(0,0,v:OBBMaxs().z + 5 + zadj)
					pos = pos:ToScreen()
					
					local alphavalue = (200 * distancemulti) - (tdist/1.5)
					alphavalue = math.Clamp(alphavalue, 0, 255)
					
					local outlinealpha = (150 * distancemulti) - (tdist/2)
					outlinealpha = math.Clamp(outlinealpha, 0, 255)
					
					local playercolour = Color(255,200,50,255)

					
										if ( (v != LocalPlayer()) and (v:GetNWBool("exclusivestatus") == false) ) then
							draw.SimpleTextOutlined(v:Name(), "Trebuchet24", pos.x, pos.y - 10, Color(playercolour.r, playercolour.g, playercolour.b, alphavalue),textalign,1,2,Color(0,0,0,outlinealpha))

										end



			end
		end
	end
end
hook.Add("HUDPaint", "DrawNameTitle", DrawNameTitle)